package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/16 14:31
 */
public class LC58最后一个单词的长度 {

    public int lengthOfLastWord(String s) {
        int k = s.length() - 1;
        while (k >= 0 && s.charAt(k) == ' ') k--;
        int n = k;
        while (k >= 0 && s.charAt(k) != ' ') k--;
        return n - k;
    }
}
